package com.gjzhao.fmmall.vo;

import org.springframework.http.HttpStatus;

/**
 * @Description: 响应状态码值(包括异常的唯一标识 / HTTP状态码 / 提示信息) - 注意：后期随着项目复杂升级，将某些问题归结成一类(比如'订单查询不到'与'商品查询不到'归结为"找不到资源")
 * @Author: gjzhao
 * @Date Created in 2021-12-05 10:42 上午
 */
public enum RespCode implements IErrorCode {

    SUCCESS(0, HttpStatus.OK, "成功"),
    RESOURCE_NOT_FOUND(1, HttpStatus.NOT_FOUND, "未找到资源"),
    FAILED(2, HttpStatus.INTERNAL_SERVER_ERROR, "失败(未知错误)"),

    REQUEST_VALIDATION_FAILED(100, HttpStatus.BAD_REQUEST, "参数检验失败"),

    LOGIN_SUCCESS(10000, HttpStatus.OK, "登录成功"),
    LOGIN_FAIL_NOT(10002, HttpStatus.NOT_FOUND, "登录不合法"),
    LOGIN_FAIL_OVERDUE(10003, HttpStatus.FORBIDDEN, "token过期"),
    ;

    /**
     * 响应码
     */
    private Integer code;

    /**
     * http状态码
     */
    private HttpStatus statusCode;

    /**
     * 提示信息
     */
    private String message;

    RespCode(Integer code, HttpStatus statusCode, String message) {
        this.code = code;
        this.statusCode = statusCode;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public HttpStatus getStatus() {
        return statusCode;
    }


    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return "RespCode{" +
            "code=" + code +
            ", statusCode=" + statusCode +
            ", message='" + message + '\'' +
            '}';
    }

}
